<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>这是div</div>
<input type="text">
<input type="button" value="平方" onclick="f()">

<script>
   function f() {
       let m=document.querySelector("div");
       let n=document.querySelector("input");

       if(isNaN(n.value)){
           m.innerText="输入错误";
       }else{
           //m.innerText=n.value*n.value;

           //将字符串转成整数或小数
           // m.innerText=parseFloat(n.value)+parseFloat(n.value);
           //n.value*1 让n.value得到的字符串*1,字符串进行-*/运算会自动转成数值
           m.innerText=n.value*1+n.value*1;
       }
   }
</script>
</body>
</html>